home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / idvb / idopen.frm < prev    next >
Text File  |  1995-05-08  |  5KB  |  192 lines

  1. VERSION 2.00
  2. Begin Form IDOPEN 
  3.    BorderStyle     =   3  'Fixed Double
  4.    Caption         =   "DlgDirList File Open"
  5.    ClientHeight    =   2490
  6.    ClientLeft      =   2670
  7.    ClientTop       =   1845
  8.    ClientWidth     =   4875
  9.    Height          =   2895
  10.    Left            =   2610
  11.    LinkMode        =   1  'Source
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    MinButton       =   0   'False
  15.    ScaleHeight     =   2490
  16.    ScaleWidth      =   4875
  17.    Top             =   1500
  18.    Width           =   4995
  19.    Begin ListBox DList 
  20.       Height          =   1395
  21.       Left            =   2040
  22.       TabIndex        =   7
  23.       Top             =   850
  24.       Width           =   1455
  25.    End
  26.    Begin ListBox FList 
  27.       Height          =   1395
  28.       Left            =   240
  29.       TabIndex        =   5
  30.       Top             =   850
  31.       Width           =   1575
  32.    End
  33.    Begin CommandButton OkCancel 
  34.       Cancel          =   -1  'True
  35.       Caption         =   "Cancel"
  36.       Height          =   375
  37.       Index           =   1
  38.       Left            =   3735
  39.       TabIndex        =   3
  40.       Top             =   675
  41.       Width           =   975
  42.    End
  43.    Begin CommandButton OkCancel 
  44.       Caption         =   "OK"
  45.       Default         =   -1  'True
  46.       Height          =   375
  47.       Index           =   0
  48.       Left            =   3720
  49.       TabIndex        =   2
  50.       Top             =   180
  51.       Width           =   975
  52.    End
  53.    Begin Label Label5 
  54.       Caption         =   "&Directories:"
  55.       Height          =   255
  56.       Left            =   2040
  57.       TabIndex        =   6
  58.       Top             =   600
  59.       Width           =   1095
  60.    End
  61.    Begin Label Label4 
  62.       Caption         =   "&Files:"
  63.       Height          =   255
  64.       Left            =   240
  65.       TabIndex        =   4
  66.       Top             =   600
  67.       Width           =   615
  68.    End
  69.    Begin Label PName 
  70.       Height          =   195
  71.       Left            =   1200
  72.       TabIndex        =   1
  73.       Top             =   240
  74.       Width           =   2355
  75.    End
  76.    Begin Label Label2 
  77.       Caption         =   "Directory:"
  78.       Height          =   255
  79.       Left            =   240
  80.       TabIndex        =   0
  81.       Top             =   240
  82.       Width           =   855
  83.    End
  84. End
  85. DefInt A-Z
  86.  
  87. Declare Function DlgDirList Lib "User" (ByVal hDlg As Integer, ByVal lpPathSpec As String, ByVal nIDListBox As Integer, ByVal nIDStaticPath As Integer, ByVal wFiletype As Integer) As Integer
  88. Declare Function DlgDirSelect Lib "User" (ByVal hDlg As Integer, ByVal lpString As String, ByVal nIDListBox As Integer) As Integer
  89. Declare Function SetErrorMode Lib "Kernel" (ByVal wMode As Integer) As Integer
  90.  
  91. ' IDs of the controls we'll be needing
  92. Const IDS_PATH = 3
  93. Const IDL_FLIST = 7
  94. Const IDL_DLIST = 8
  95.  
  96. ' search spec
  97. Const sFileSpec = "*.*"
  98.  
  99. ' last change flags
  100. Const FListBox = 1
  101. Const DListBox = 2
  102.  
  103. ' iChange holds the last change flag
  104. Dim iChange As Integer
  105.  
  106. '  sCurDir holds the most recent directory
  107. Dim sCurDir As String
  108.  
  109. Sub DList_Click ()
  110.     iChange = DListBox
  111. End Sub
  112.  
  113. Sub DList_DblClick ()
  114.  
  115.     ' Prepare a buffer to hold the new directory
  116.     aDir$ = String$(15, 0)
  117.  
  118.     ' get the new directory
  119.     Ok = DlgDirSelect(IDOPEN.hWnd, aDir$, IDL_DLIST)
  120.  
  121.     ' get rid off the Chr$(0)s
  122.     aDir$ = Left$(aDir$, InStr(aDir$, Chr$(0)) - 1)
  123.  
  124.     ' let Windows handle the errors, e.g. drive not ready, etc
  125.     iErrMode = SetErrorMode(0)
  126.  
  127.     ' perform the changes
  128.     Ok = DlgDirList(IDOPEN.hWnd, (aDir$ + sFileSpec), IDL_FLIST, IDS_PATH, 0)
  129.     Ok = DlgDirList(IDOPEN.hWnd, "*.*", IDL_DLIST, 0, &HC010)
  130.  
  131.     ' give error control back to us
  132.     iErrMode = SetErrorMode(1)
  133.  
  134.     ' save the directory change
  135.     sCurDir = LCase$(MakePath$(CurDir$))
  136.  
  137. End Sub
  138.  
  139. Sub FList_Click ()
  140.     iChange = FListBox
  141. End Sub
  142.  
  143. Sub FList_DBlClick ()
  144.  
  145.     ' if there is a selection, retrieve it and change the IDDEMO
  146.     ' FName caption to show the full selection
  147.  
  148.     If FList.ListIndex <> -1 Then
  149.     IDDEMO.FName.Caption = sCurDir + FList.List(FList.ListIndex)
  150.     IDOPEN.Hide
  151.     End If
  152.  
  153. End Sub
  154.  
  155. Sub Form_Load ()
  156.     
  157.     ' fill the listboxes (wFileSpec is set to 0 for normal files)
  158.     
  159.     Ok = DlgDirList(IDOPEN.hWnd, sFileSpec, IDL_FLIST, IDS_PATH, 0)
  160.  
  161.     Ok = DlgDirList(IDOPEN.hWnd, "*.*", IDL_DLIST, 0, &HC010)
  162.     
  163.     ' save the current directory
  164.     sCurDir = LCase$(MakePath$(CurDir$))
  165.  
  166. End Sub
  167.  
  168. Function MakePath$ (aPath$)
  169.  
  170.     If Right$(aPath$, 1) <> "\" Then
  171.     MakePath$ = aPath$ + "\"
  172.     Else
  173.     MakePath$ = aPath$
  174.     End If
  175.  
  176. End Function
  177.  
  178. Sub OkCancel_Click (Index As Integer)
  179.     If Index = 0 Then
  180.     Select Case iChange
  181.         Case DListBox
  182.         DList_DblClick
  183.         Case FListBox
  184.         FList_DBlClick
  185.         Case Else
  186.     End Select
  187.     Else
  188.     IDOPEN.Hide
  189.     End If
  190. End Sub
  191.  
  192.